package doudizhu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 斗地主生成牌  洗牌 发牌
 */
public class GameDemo {
    //定义集合存储牌
    private static List<Card>  allCard = new  ArrayList<>();
    static {
        //代码块生成牌
        String[] sizes = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors = {"♣","♥","♦","♠"};
        for (int i = 0; i < sizes.length; i++) {
            for (int j = 0; j < colors.length; j++) {
                Card card = new Card(sizes[i],colors[j],i);
                allCard.add(card);
            }
        }
        //加上大小王
        Card min = new Card("小王","🐵",sizes.length);
        Card max = new Card("大王","🐵",sizes.length+1);
        Collections.addAll(allCard,min,max);
    }

    public static void main(String[] args) {
        //随机打打乱牌
        Collections.shuffle(allCard);

        //定义三个玩家
        ArrayList<Card> zs1 = new ArrayList<>();
        ArrayList<Card> zs2 = new ArrayList<>();
        ArrayList<Card> zs3 = new ArrayList<>();
        //发牌 留三张底牌
        for (int i = 0; i < allCard.size() - 3; i++) {
            if(i%3==0) {
                zs1.add(allCard.get(i));
            }else if(i%3==1) {
                zs2.add(allCard.get(i));
            }else if(i%3==2) {
                zs3.add(allCard.get(i));
            }
        }
        //对玩家牌进行从大到小排序
        sortCard(zs1);
        sortCard(zs2);
        sortCard(zs3);

        //三张底牌
        List<Card> threeCard = allCard.subList(allCard.size() -3, allCard.size());

        //Collections 家族包块 List(ArrayList LinkList)  Set (HashSet(LinkSet)  TreeSet)
        //Map家族

        System.out.println(allCard);
        System.out.println(zs1);
        System.out.println(zs2);
        System.out.println(zs3);
        System.out.println(threeCard);
    }

    public static void sortCard(List<Card> cards) {
        Collections.sort(cards, (o1, o2) -> o2.getIndex() - o1.getIndex());
    }
}
